<?php

namespace app\controllers;

use yii\web\Controller;
use yii\web\Cookie;

class HelloController extends Controller
{
    public $layout = 'common';

    public function actionIndex()
    {
        // 视图
        //return $this->renderPartial('index');

        // 加载数据
        //$hello_str = 'Hello God!';
        //$test_arr = array(1, 2);
        //$data = array();
        //$data['view_hello_str'] = $hello_str;
        //$data['view_test_arr'] = $test_arr;
        //return $this->renderPartial('index', $data);

        // 过滤数据
        //$hello_str = 'Hello God! <script>alert("Hello God!")</script>';
        //$data = array();
        //$data['view_hello_str'] = $hello_str;
        //return $this->renderPartial('index', $data);

        // 布局
        return $this->render('index'); // content
    }
    /*
    public function actionIndex()
    {
        //COOKIE
        //$cookies = \Yii::$app->response->cookies;

        //$cookie_data = array('name' => 'user', 'value' => 'zhangsi');
        //$cookies->add(new Cookie($cookie_data));
        //$cookies->remove('user');

        $cookies = \Yii::$app->request->cookies;
        //echo $cookies->get('user');
        echo $cookies->getValue('user', '默认值');
    }
    */
    /*
    public function actionIndex()
    {
        //SESSION
        $session = \Yii::$app->session;

        $session->open();
        //if ($session->isActive) {
        //    echo 'session is open';
        //}
        //$session->set('user', '张三');
        //echo $session->get('user');
        //$session->remove('user');

        //$session['user'] = '张三';
        //echo $session['user'];
        unset($session['user']);
    }
    */
    /*
    public function actionIndex()
    {
        // 响应
        $res = \Yii::$app->response;

        //$res->setStatusCode(404);
        //$res->headers->add('pragma', 'no-cache');
        //$res->headers->set('pragma', 'max-age=5');
        //$res->headers->remove('pragma');

        // 跳转
        //$res->headers->add('Location', 'http://www.baidu.com');
        //$this->redirect('http://www.baidu.com', 302);

        // 文件下载
        //$res->headers->add('Content-disposition', 'attachment; filename="./robots.txt"');
        $res->sendFile("./robots.txt");
    }
    */
    /*
    public function actionIndex()
    {
        // 请求
        $request = \Yii::$app->request;
        //echo $request->get('id', 20);

        if ($request->isGet) {
            echo 'this is get method';
        }
        //echo 'Hello World';
    }
    */
}